/*
 * Composition Knowledge Miner. A data mashup composition knowledge miner
 * Copyright (C) 2011 Carlos Rodriguez
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package eu.ict_omelette.mashup.compositionminer;

import eu.ict_omelette.mashup.canonicalmodel.CanonicalMashup;
import eu.ict_omelette.mashup.canonicalmodel.Component;
import eu.ict_omelette.mashup.canonicalmodel.Dataflow;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author carlos
 */
public class ConnectorPatternMiner {
    private LinkedList<CanonicalMashup> compRepo;
    
    public ConnectorPatternMiner(LinkedList<CanonicalMashup> compRepo){
        this.compRepo = compRepo;
    }

    public List<CanonicalMashup> mine(Double minSupDf, Double minSupDm){
        LinkedList<CanonicalMashup> result = new LinkedList();

        LinkedList<LinkedList> db = new LinkedList();
        LinkedHashMap<String, LinkedList> hashRecConn = Util.getRecurrentConnectors(compRepo, minSupDf);
        LinkedHashMap<String, LinkedList> globalItemset = new LinkedHashMap();
        LinkedList<Dataflow> conInst = Util.getConnectorInstances(this.compRepo, hashRecConn);

        Iterator<Dataflow> itConIns = conInst.iterator();
        while(itConIns.hasNext()){
            Dataflow df = itConIns.next();
            Component toComp = df.getToComponent();
            Component fromComp = df.getFromComponent();

            CanonicalMashup cm = new CanonicalMashup();
            cm.setId("");
            cm.setName("");
            cm.setSrc("");

            cm.addComponent(fromComp);
            cm.addComponent(toComp);

            cm.addDataflow(df);

            result.add(cm);
        }

        return result;
    }

}
